package com.daguchuangyi.erp_android.productlist.widget;

import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.widget.TextView;

import com.daguchuangyi.erp_android.R;
import com.daguchuangyi.erp_android.productlist.ProductSummaryManager;
import com.daguchuangyi.erp_android.productlist.select.SelectProductActivity;

/**
 * Created by lijianjian on 2018/3/11.
 */

public class TempFloatView extends ConstraintLayout {
    private TextView mCountTv;

    public TempFloatView(Context context) {
        super(context);
        init(context);
    }

    public TempFloatView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public TempFloatView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.view_temp_float_layout, this);
        mCountTv = findViewById(R.id.count_tv);
        setOnClickListener(v -> {
//            if (ProductSummaryManager.getInstance().getCheckedProudctIdList().size() == 0) {
//                JUtils.Toast("还没有选中任何条目");
//            } else {
            Intent intent = new Intent(getContext(), SelectProductActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getContext().startActivity(intent);
//            }
        });
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        int size = ProductSummaryManager.getInstance().getCheckedProudctIdList().size();
        setCount(size);
    }

    public void setCount(int count) {
        if (count > 0) {
            mCountTv.setVisibility(VISIBLE);
            mCountTv.setText(String.valueOf(count));
        } else {
            mCountTv.setVisibility(GONE);
        }
    }

}
